<template>
  <svg :class="svgClass" aria-hidden="true" v-bind="$attrs" :style="{fontSize: size+'!important'}">
    <use :xlink:href="iconName" :fill="color"/>
  </svg>
</template>

<script setup>
import {computed} from 'vue'
const props = defineProps({
  // SVG 图标名称或在线URL
  name: {
    type: String,
    required: true
  },
  color: {
    type: String,
    default: ''
  },
  size: {
    type: String,
    default: '20'
  }
})
// 补全
const iconName = computed(() => `#icon-${props.name}`)
const svgClass = computed(() => {
  if (props.name) {
    return 'svg-icon ' + props.name
  } else {
    return 'svg-icon'
  }
})
</script>

<style lang="scss" scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>